package com.punai.externalccb.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.punai.common.core.domain.BaseEntity;
import com.punai.common.utils.spring.SpringUtils;
import com.punai.externalccb.bo.YdCbfeeiteminfoStandardBo;
import com.punai.externalccb.constants.CCBConstants;
import com.punai.externalccb.domain.YdCbfeeiteminfoStandard;
import com.punai.externalccb.mapper.YdCbfeeiteminfoStandardMapper;
import com.punai.externalccb.service.IYdCbfeeiteminfoStandardService;
import com.punai.monthanalysis.constants.YdcbfxConstants;
import com.punai.monthanalysis.service.ProYdcbfxTabsService;
import com.punai.monthanalysis.sqliteDao.CostStructureCategoryRepository;
import com.punai.monthanalysis.vo.TableListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class IYdCbfeeiteminfoStandardServiceImpl extends ServiceImpl<YdCbfeeiteminfoStandardMapper, YdCbfeeiteminfoStandard> implements IYdCbfeeiteminfoStandardService {
    @Autowired
    private YdCbfeeiteminfoStandardMapper ydCbfeeiteminfoStandardMapper;
    @Autowired
    private CostStructureCategoryRepository costStructureCategoryRepository;

    @Override
    public List<? extends BaseEntity> getTabsDataList(String proId, TableListVo vo) {
        List<YdCbfeeiteminfoStandardBo> res = new ArrayList<>();
        String monthId = vo.getMonthId();//期次Id
        String dataType = "2";//费用项
        String feeType = YdcbfxConstants.TABS_TYPE.getFeeType(vo.getType());

        boolean searchAll = YdcbfxConstants.TABS_TYPE.DWGC_CSF_FXB.getFeeType().equals(feeType);

        List<YdCbfeeiteminfoStandard> selectList = ydCbfeeiteminfoStandardMapper.selectList(Wrappers.<YdCbfeeiteminfoStandard>lambdaQuery()
                .eq(YdCbfeeiteminfoStandard::getProId,proId)
                .eq(YdCbfeeiteminfoStandard::getYdDate, monthId)
                .eq(YdCbfeeiteminfoStandard::getStagetype, CCBConstants.CCB_TYPE.YDCBFX.getCode())
                .eq(!searchAll,YdCbfeeiteminfoStandard::getDataType, dataType)
                .eq(YdCbfeeiteminfoStandard::getFeeType, feeType));
        List<YdCbfeeiteminfoStandard> categoryList = ydCbfeeiteminfoStandardMapper.selectList(Wrappers.<YdCbfeeiteminfoStandard>lambdaQuery()
                .eq(YdCbfeeiteminfoStandard::getProId, proId)
                .eq(YdCbfeeiteminfoStandard::getYdDate, monthId)
                .eq(YdCbfeeiteminfoStandard::getStagetype, CCBConstants.CCB_TYPE.YDCBFX.getCode())
                .eq(!searchAll, YdCbfeeiteminfoStandard::getDataType, "1")
                .eq(YdCbfeeiteminfoStandard::getFeeType, feeType)
                );
//        .isNotNull(YdCbfeeiteminfoStandard::getUnit)
        ProYdcbfxTabsService bean = SpringUtils.getBean(YdcbfxConstants.TABS_TYPE.getActuator(vo.getType()));
        return bean.getTabsDataList(proId,monthId,selectList,categoryList);
    }
}
